Pecl.installExtensions   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 10
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
dl 0
loc 10
rs 9.9
c 0
b 0
f 0
1
import execa from 'execa'
2
import {info} from '../utils/console'
3
import Apcu from './php/apcu'
4
import Geoip from './php/geoip'
5
import Memcached from './php/memcached'
6
import Xdebug from './php/xdebug'
7
import Yaml from './php/yaml'
8
9
class Pecl {
10
    /**
11
     * All extensions available in Jale.
12
     */
13
    static PHP_EXTENSIONS = [
14
        Apcu,
15
        Geoip,
16
        Memcached,
17
        Xdebug,
18
        Yaml
19
    ]
20
21
    /**
22
     * Get the path of the extension directory currently used by PECL.
23
     */
24
    static getExtensionDirectory = async (): Promise<string> => {
25
        const {stdout} = await execa('pecl', ['config-get', 'ext_dir'])
26
        let directory = stdout.replace('\n', '').trim()
27
28
        if (directory.indexOf('/Cellar/') !== -1)
29
            directory = directory.replace('/lib/php/', '/pecl/')
30
31
        return directory
32
    }
33
34
    /**
35
     * Install all extensions supported by Jale. Set optionals to true to also include optional extensions.
36
     *
37
     * @param optionals
38
     */
39
    static installExtensions = async (optionals = false): Promise<void> => {
40
        info('Installing PECL extensions...')
41
42
        for (const extension of Pecl.PHP_EXTENSIONS) {
43
            const ext = new extension
44
            if (!optionals && !ext.default)
45
                continue
46
47
            await ext.install()
48
            await ext.enable()
49
        }
50
    }
51
52
    /**
53
     * Uninstall all extensions supported by Jale. Set optionals to true to also include optional extensions.
54
     *
55
     * @param optionals
56
     */
57
    static uninstallExtensions = async (optionals = false): Promise<void> => {
58
        info('Uninstalling PECL extensions...')
59
60
        for (const extension of Pecl.PHP_EXTENSIONS) {
61
            const ext = new extension
62
            if (!optionals && !ext.default)
63
                continue
64
65
            await ext.uninstall()
66
            await ext.disable()
67
        }
68
    }
69
}
70
71
export default Pecl